package com.ryskoo.controller.basicdata;

import java.util.List;

import com.ryskoo.basicdata.mallinfo.domain.MallInfoPO;
import com.ryskoo.basicdata.mallinfo.service.IMallInfoService;
import com.ryskoo.framework.core.bean.ReturnMessageDTO;
import com.ryskoo.framework.core.controller.BasicHandler;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

/**
 * 商城信息
 * @author BeHappy
 */
@Controller
@RequestMapping("/vendor/basicdata/mallinfo")
public class MallInfoController extends BasicHandler<MallInfoPO> {
    private static final String TEMPLATE_PATH = "system/basicdata/mallinfo";

    private static final String MODULE_NAME = "MallInfo";

    private IMallInfoService mallInfoService;

    /**
     * 基类构造方法.
     */
    public MallInfoController() {
        super(TEMPLATE_PATH, MODULE_NAME);
    }

    /**
     * 消费者注入
     *
     * @param mallInfoConsumer 消费者基类
     */
    @Autowired
    protected void setService(IMallInfoService mallInfoService) {
        this.mallInfoService = mallInfoService;
        super.setService(mallInfoService);
    }

    /**
     * 跳转设置页面
     *
     * @param model 页面模型 {@link Model}
     * @return 页面模板路径
     */
    @GetMapping("/tosetting")
    public String tosetting(Model model) {
    	MallInfoPO po = null;
    	List<MallInfoPO> list = mallInfoService.getAll();
    	if (list != null && list.size() > 0) {
    		po = list.get(0);
    	}
        model.addAttribute("dto", po);
        return TEMPLATE_PATH + "/" + MODULE_NAME + "Setting";
    }

    /**
     * 编辑
     *
     * @param dto
     *            编辑的对象 {@link MallInfoDTO}
     * @return 统一返回消息 {@link ReturnMessageDTO}
     */
    @PostMapping("/setting")
    @ResponseBody
    public ReturnMessageDTO setting(@RequestBody MallInfoPO po) {
        return super.edit(po);
    }
}
